from django.db import models

# Create your models here.

class Menu(models.Model):
    name = models.CharField(verbose_name='菜单名', max_length=20)
    superior = models.SmallIntegerField('上级菜单', null=True)  # 空，没有上级菜单，值，它有上级菜单，并且值就是上级菜单的id
    status = models.SmallIntegerField(default=0)  # 0：正常;1：删除
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)

    class Meta:
        db_table = 'menu'

    def __str__(self):
        return '%s-%s' % (self.name, self.superior)


# 商品
class Commodity(models.Model):
    title = models.TextField('标题')
    subtitle = models.TextField('副标题')
    cover_picture = models.TextField('封面图')
    status = models.SmallIntegerField(default=0)
    priority = models.IntegerField(default=100)  # 值越小，优先级越高
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)
    menu = models.ForeignKey('Menu', related_name='commodity', on_delete=models.SET_NULL, null=True)
    column = models.ForeignKey('Column', related_name='commodity', on_delete=models.SET_NULL, null=True)

    class Meta:
        db_table = 'commodity'

    def __str__(self):
        return '%s-%s' % (self.title, self.subtitle)


# 栏目
class Column(models.Model):
    name = models.CharField('栏目名', max_length=40)  # 有好货、猜你喜欢、节假日优惠
    status = models.SmallIntegerField(default=0)
    priority = models.IntegerField(default=100)  # 值越小，优先级越高
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)

    class Meta:
        db_table = 'column'

    def __str__(self):
        return '%s' % self.name


# 商品选项
class CommodityOptions(models.Model):
    option_name = models.CharField('选项名', max_length=40)  # 颜色分类、适用床尺寸
    options = models.TextField('选项')  # eg：绿色、蓝色、红色
    price = models.FloatField(null=True)
    inventory = models.IntegerField('库存', null=True)
    img = models.TextField('商品选项图', null=True)
    status = models.SmallIntegerField(default=0)
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)
    commodity = models.ForeignKey('Commodity', on_delete=models.CASCADE)

    class Meta:
        db_table = 'commodity_options'

    def __str__(self):
        return '%s-%s' % (self.option_name, self.options)


# 商品图片
class CommodityImage(models.Model):
    src = models.TextField('图片地址')
    belong = models.SmallIntegerField('图片所属位置')  # 0：展示图；1：详情图
    status = models.SmallIntegerField(default=0)
    priority = models.IntegerField(default=100)  # 值越小，优先级越高
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)
    commodity = models.ForeignKey('Commodity', on_delete=models.CASCADE)

    class Meta:
        db_table = 'commodity_image'